<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>开灯and关灯</title>
</head>
<body >
<input type="button" onclick="on()" value="开灯">
<img id="myImafe" border="0" src="../img/off.gif" style="text-align: center">
<input type="button" onclick="off()" value="关灯" >
<script>
    function on(){
        document.getElementById('myImafe').src='../img/on.gif';
    };
    function off(){
        document.getElementById('myImafe').src='../img/off.gif';
    };
    var x=0;
    setInterval(function (){
        if (x % 2==0){
            on();
        }else {
            off();
        }
        x++;
    },);
</script>
</body>
</html>